//
//  MBCustomNavView.m
//  Meboo
//
//  Created by kyo on 2023/10/21.
//

#import "MBCustomNavView.h"
@interface MBCustomNavView ()

@end

@implementation MBCustomNavView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public
- (void)setIsBigTitle:(BOOL)isBigTitle {
    _isBigTitle = isBigTitle;
    self.titleLab.font = MBKouFontSizeScale(30);
    [self.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.leftBtn).offset(MBWidthScale(-5));
    }];
}

- (void)setIsWhiteBack:(BOOL)isWhiteBack {
    _isWhiteBack = isWhiteBack;
    [self.leftBtn setImage:ImageWithName(@"wholikeme_back_icon") forState:0];
    [self.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(MBWidthScale(10));
        make.height.mas_equalTo(MBHeightScale(17));
        make.left.mas_equalTo(MBWidthScale(36));
        make.bottom.mas_equalTo(MBHeightScale(-12));
    }];
}

- (void)setIsPop:(BOOL)isPop {
    _isPop = isPop;
}


#pragma mark - Action

- (void)rightAction {
    if (self.rightBlock) {
        self.rightBlock();
    }
}

- (void)leftAction {
    if (self.isPop) {
        if (self.popBlock) {
            self.popBlock();
        }
    } else {
        [self.currentViewController.navigationController popViewControllerAnimated:YES];;
    }
}

#pragma mark - UI
- (void)setupUI {
    
    self.backgroundColor = HEXS(@"22253C");
    
    [self addSubview:self.rightBtn];
    [self.rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(MBWidthScale(-20));
        make.bottom.mas_equalTo(MBHeightScale(-5));
        make.width.height.mas_equalTo(MBHeightScale(30));
    }];
    
    [self addSubview:self.leftBtn];
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(20));
        make.bottom.mas_equalTo(MBHeightScale(-5));
        make.width.height.mas_equalTo(MBHeightScale(30));
    }];
    
    [self addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self.leftBtn);
    }];

}

#pragma mark - Setter && Getter
- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [[UIButton alloc] init];
        _leftBtn.layer.cornerRadius = MBHeightScale(30/2);
        [_leftBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_leftBtn setImage:ImageWithName(@"chat_back") forState:0];
        [_leftBtn addTarget:self action:@selector(leftAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftBtn;
}

- (UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [[UIButton alloc] init];
        _rightBtn.layer.cornerRadius = MBHeightScale(30/2);
        [_rightBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        _rightBtn.hidden = YES;
        [_rightBtn addTarget:self action:@selector(rightAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightBtn;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.font = MBHelBoldFontSizeScale(20);
        _titleLab.textColor = UIColor.whiteColor;
    }
    return _titleLab;
}

@end
